package edu.rit.drh4818.raytracing.light;

import java.awt.Color;

/**
 * A collection of Color manipulation methods.
 * 
 * @author Darren Headrick
 *
 */
public class ColorMixer 
{
	
	/**
	 * Multiply base color by some constant.
	 * 
	 * @param base Base color.
	 * @param value Multiplier.
	 * @return Individual color components multiplied by value.
	 */
	public static Color multiply( Color base, double value )
	{
		value = Math.abs( value );
		float r = (float)(base.getRed()/255F * value);
		float g = (float)(base.getGreen()/255F * value);
		float b = (float)(base.getBlue()/255F * value);
		
		if( r > 1 ) r = 1; if( g > 1 ) g = 1; if( b > 1 ) b = 1;
		return new Color(r,g,b);
	}
	
	/**
	 * Multiply two colors together.
	 * 
	 * @param c1 Color 1
	 * @param c2 Color 2
	 * @return The individual color components multiplied together.
	 */
	public static Color multiply( Color c1, Color c2 )
	{
		float red = c1.getRed()/255F *c2.getRed()/255F;
		float green = c1.getGreen()/255F * c2.getGreen()/255F;
		float blue = c1.getBlue()/255 * c2.getBlue()/255;
		return new Color(red,green,blue);
	}
	
	/**
	 * Add the two colors together.
	 * if( any sum is larger then set it to 255.
	 * 
	 * @param color1 First color to add up.
	 * @param color2 Second color to add up.
	 * @return The two colors added together.
	 */
	public static Color add( Color color1, Color color2 )
	{
		int red = color1.getRed() + color2.getRed();
		int green = color1.getGreen() + color2.getGreen();
		int blue = color1.getBlue() + color2.getBlue();
		
		if( red > 255 ) red = 255;
		if( green > 255 ) green = 255;
		if( blue > 255 ) blue = 255;
		
		return new Color( red, green, blue);
	}
	
	/**
	 * Return maximum value between two lights.
	 * @param color1
	 * @param color2
	 * @return
	 */
	public static Color max( Color color1, Color color2 )
	{
		return new Color( 
				Math.max( color1.getRed(), color2.getRed() ),
				Math.max( color1.getGreen(), color2.getGreen() ),
				Math.max( color1.getBlue(), color2.getBlue() ) );
	}
}
